#ifndef CYCLELIST_H
#define CYCLELIST_H

#include <iostream>
using namespace std;

struct Node
{
    int index = 0;
    Node *next;
};

class cyclelist
{
private:
    Node *head;
    Node *tail;
    int size = 0;

public:
    cyclelist()
    {
        head = nullptr;
        tail = nullptr;
        size = 0;
    }

    void push(Node *node)
    {
        if (head == nullptr)
        {
            head = node;
            tail = node;
            node->next = nullptr;
        }
        else
        {
            tail->next = node;
            node->next = head;
            tail = node;
        }
        size++;
    }

    void pop(int gap)
    {
        Node *current = head;
        while (size > 1)
        {
            for (int i = 1; i < gap - 1; i++)
            {
                current = current->next;
            }
            Node *to_delete = current->next;
            current->next = current->next->next;
            delete to_delete;
            current = current->next;
            size--;
        }
        head = current;
    }

    void print()
    {
        Node *current = head;
        if (size == 1)
        {
            cout << current->index;
        }
    }
};
#endif;
